<?php
namespace Home\Controller;
use Think\Controller;
use Think\Upload;
class MemberPublicController extends Controller {
	/**
	 * 构造方法
	 * 功能：公共变量赋值，初始化公共类
	 * 日期：2014-8-15
	 * 作者：zx
	 */
	function __construct() {
		parent::__construct();
		$pub_va = A('Public');
		$pub_va -> login_check();
	}

	/**
	 * 功能：公众号列表
	 * 日期：2014-8-14
	 * 作者：zx
	 */
	public function lists() {
		$MemberPublic = D('MemberPublic');
		$MemberPublic_list = $MemberPublic -> getMemberPublic($_SESSION['member']['uid']);
		$this -> assign('MemberPublic_list', $MemberPublic_list);
		$this -> display();
	}

	public function nowpub() {
		$id = I('get.id');
		$MemberPublic = D('MemberPublic');
		$menu_p_list = $MemberPublic -> where("id='$id'") -> find();
		session("now_pub", $menu_p_list);
		$this -> display('Index/index');
	}

	/**
	 * 功能：公众号配置帮助
	 * 日期：2014-8-14
	 * 作者：zx
	 */
	public function help() {
		$this -> display();
	}

	/**
	 * 功能：公众号添加界面
	 * 日期：2014-8-14
	 * 作者：zx
	 */
	public function public_add_process() {
		$list = I('post.');
		$config = array('maxSize' => 1024000, 'rootPath' => './Public/', 'savePath' => '/uploads/headface/' . $_SESSION['member']['email'] . '/', 'saveName' => $list['public_id'], 'replace' => 'true', 'exts' => array('jpg', 'gif', 'png', 'jpeg'), 'subName' => $list['public_id'], );
		delDirAndFile($_SERVER['DOCUMENT_ROOT'] . __ROOT__ . "/Public/uploads/headface/" . $_SESSION['member']['email'] . '/' . $list['public_id']);
		$upload = new \Think\Upload($config);
		$info = $upload -> upload();
		if (!$info) {
			$this -> error($upload -> getError());
		} else {
			$file = $info['headface_url'];
			$sqlPath = $file['savepath'] . $file['savename'];
			$list['headface_url'] = $sqlPath;
			$list['uid'] = $_SESSION['member']['uid'];
			$list['token'] = "weiapp";
			$MemberPublicModel = D('MemberPublic');
			$result = $MemberPublicModel -> add($list);
			$this -> success('新增成功', 'lists');
		}
	}

	public function del($public_id) {
		$MemberPublicModel = D('MemberPublic');
		$result = $MemberPublicModel -> delete_pm($public_id);
		delDirAndFile($_SERVER['DOCUMENT_ROOT'] . __ROOT__ . "/Public/uploads/headface/" . $_SESSION['member']['email'] . '/' . $public_id);
		return true;
	}

	public function delete_public_member() {
		$public_id = I('get.public_id');
		if ($this -> del($public_id)) {
			$this -> success('删除成功', 'lists');
		} else {
			$this -> error('删除失败');
		}
	}

	public function delete_public_members() {
		$public_id = I('get.public_id');
		$public_id = substr($public_id, 0, -1);
		$numbers = explode(",", $public_id);
		foreach ($numbers as $value) {
			$this -> del($value);
		}
		echo "true";
	}

	public function edit() {
		$id = I('get.id');
		$MemberPublicModel = D('MemberPublic');
		$result = $MemberPublicModel -> where("id='$id'") -> find();
		$this -> assign('MemberPublic_list', $result);
		$this -> display();
	}

	public function edit_process() {
		$list = I('post.');
		if (!empty($_FILES['headface_url']['name'])) {
			$config = array('maxSize' => 1024000, 'rootPath' => './Public/', 'savePath' => '/uploads/headface/' . $_SESSION['member']['email'] . '/', 'saveName' => $list['public_id'], 'replace' => 'true', 'exts' => array('jpg', 'gif', 'png', 'jpeg'), 'subName' => $list['public_id'], );
			delDirAndFile($_SERVER['DOCUMENT_ROOT'] . __ROOT__ . "/Public/uploads/headface/" . $_SESSION['member']['email'] . '/' . $list['public_id']);
			$upload = new \Think\Upload($config);
			$info = $upload -> upload();
			if (!$info) {
				$this -> error($upload -> getError());
			} else {
				$file = $info['headface_url'];
				$sqlPath = $file['savepath'] . $file['savename'];
				$list['headface_url'] = $sqlPath;
				$list['uid'] = $_SESSION['member']['uid'];
				$list['token'] = "weiapp";
				$MemberPublicModel = D('MemberPublic');
				if ($MemberPublicModel -> edit($list['id'], $list)) {
					$this -> success('更新成功！', 'lists');
				} else {
					$this -> error('更新失败！');
				}
			}
		} else {
			$list['token'] = "weiapp";
			$MemberPublicModel = D('MemberPublic');
			if ($MemberPublicModel -> edit($list['id'], $list)) {
				$this -> success('更新成功！', 'lists');
			} else {
				$this -> error('更新失败！');
			}
		}
	}

	public function menu() {
		$installiert_plug = D('installiert_plug');
		$plug = D('plug');
		$menu = D('menu');
		$pub_id = $_SESSION['now_pub']['id'];
		$uid=$_SESSION['member']['uid'];
		$installiert_plug_list = $installiert_plug -> where("pub_id='$pub_id' and uid='$uid' and isunlock=1") -> select();
		foreach ($installiert_plug_list as $key => $val) {
			$id = $val['p_id'];
			$p_m_l[$key] = $plug -> where("id='$id'") -> select();
		}
		$mp_id = $_SESSION['now_pub']['id'];
		$menu_list = $menu -> where("mp_id='$mp_id'") -> order('path') -> select();
		$this -> assign('menu_list', $menu_list);
		$this -> assign('p_m_l', $p_m_l);
		$this -> display();
	}

	public function save_menu($list) {
		$menu = D('menu');
		//$list = I('post.');
		$num = 0;
		$key = 0;
		foreach ($list as $val) {
			switch ($key++) {
				case 0 :
					$data[$num]['mp_id'] = $val;
					break;
				case 1 :
					$data[$num]['path'] = $val;
					break;
				case 2 :
					$data[$num]['name'] = $val;
					break;
				case 3 :
					$data[$num]['menu'] = $val;
					break;
				case 4 :
					$data[$num]['grade'] = $val;
					break;
				case 5 :
					$data[$num++]['type'] = $val;
					$key = 0;
					break;
			}
		}
		$pub_id = $_SESSION['now_pub']['id'];
		$menu -> where("mp_id='$pub_id'") -> delete();
		foreach ($data as $val1) {
			$menu -> add($val1);
		}
	}

	function create_menu() {
		$list = I('post.');
		$num = 0;
		$key = 0;
		foreach ($list as $val) {
		    $data[$num]['type']='';
		    switch ($key++) {
		        case 2 :
		            $data[$num]['name'] = urlencode($val);
		            break;
		        case 3 :
		            $data[$num]['key'] = urlencode($val);
		            break;
		        case 4 :
		            $data[$num]['grade'] = urlencode($val);
		            break;
		        case 5 :
		            if($val=="view"){
		                $a=substr($data[$num]['key'],0,4);
		                $data[$num]['url'] = $data[$num]['key'];
		                if($a!="http"){
		                    $data[$num]['url']="http://".$_SERVER['SERVER_NAME']."/plug".$data[$num]['key'];
		                }else
		                unset($data[$num]['key']);
		            }
		            //echo $data[$num]['url'];
		            $data[$num++]['type'] = urlencode($val);
		            $key = 0;
		            break;
		    }
		}
		$menu['button']='';
		$n_1=0;
		$n=1;
		$key1=0;
		foreach ($data as $key=>$item1){
		    if($item1['grade']==1){
		        unset($item1['grade']);
		        $menu['button'][$key1++]=$item1;
		        $n_1=0;
		        //dump($item1);
		    }else if($item1['grade']==2){
		        unset($menu['button'][$key-$n]['type']);
		        unset($menu['button'][$key-$n]['key']);
		        unset($item1['grade']);
		        $menu['button'][$key-$n]["sub_button"][$n_1++]=$item1;
		        $n++;
		    }
		}
		$jsonmenu=urldecode(json_encode($menu));
		//dump($jsonmenu);
		$access_token=get_accesstoken();
        // echo $access_token;
        //dump($_SESSION['now_pub']);
		$url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token;
		$result = https_request($url, $jsonmenu);
        $errcode=objtoarr(json_decode($result));
        if($errcode['errmsg']=="ok"){
            $this->save_menu($list);
            $this -> success('菜单已生成！', 'menu');
        }else{
            $this -> error('更新失败！错误代码为'.$errcode['errcode']);
        }
	}
	public function subscribe(){
	    $this->display();
	}
    public function subscribe_pro(){
        $data=I("post.");
        switch ($data['msgtype']){
            case 'text':
                $this->subscribe_add($data);
                break;
            case 'image':
                $config = array(
                'maxSize' => 1024000,
                 'rootPath' => './Public/',
                 'savePath' => '/uploads/subscribe/' . $_SESSION['member']['email'] . '/',
                 'saveName' => $data['public_id'],
                 'replace' => 'true',
                 'exts' => array('jpg'),
                 'subName' => $data['public_id'],
                 );
                $this->up_meiti($config,$data);
                break;
                case 'voice':
                    $config = array(
                    'maxSize' => 1024000,
                    'rootPath' => './Public/',
                    'savePath' => '/uploads/subscribe/' . $_SESSION['member']['email'] . '/',
                    'saveName' => $data['public_id'],
                    'replace' => 'true',
                    'exts' => array('amr','mp3'),
                    'subName' => $data['public_id'],
                    );
                    $this->up_meiti($config,$data);
                    break;
                    case 'video':
                        $config = array(
                        'maxSize' => 10240000,
                        'rootPath' => './Public/',
                        'savePath' => '/uploads/subscribe/' . $_SESSION['member']['email'] . '/',
                        'saveName' => $data['public_id'],
                        'replace' => 'true',
                        'exts' => array('amr','mp4'),
                        'subName' => $data['public_id'],
                        );
                        $this->up_meiti($config,$data);
                        break;
                        case 'thumb':
                            $config = array(
                            'maxSize' => 10240000,
                            'rootPath' => './Public/',
                            'savePath' => '/uploads/subscribe/' . $_SESSION['member']['email'] . '/',
                            'saveName' => $data['public_id'],
                            'replace' => 'true',
                            'exts' => array('amr','mp3','jpg'),
                            'subName' => $data['public_id'],
                            );
                            $this->up_meiti($config,$data);
                            break;
                            case 'news':
                                $config = array(
                                'maxSize' => 10240000,
                                'rootPath' => './Public/',
                                'savePath' => '/uploads/subscribe/' . $_SESSION['member']['email'] . '/',
                                'saveName' => $data['public_id'],
                                'replace' => 'true',
                                'exts' => array('jpg'),
                                'subName' => $data['public_id'],
                                );
                                delDirAndFile($_SERVER['DOCUMENT_ROOT'] . __ROOT__ . "/Public/uploads/subscribe/" . $_SESSION['member']['email'] . '/' . $data['public_id']);
	    $upload = new \Think\Upload($config);
	    $info = $upload -> upload();
	    if (!$info) {
	        $this -> error($upload -> getError());
	    } else {
	        $file = $info['file'];
	        $data['picurl'] = $arr['__PUBLIC__'].$file['savepath'] . $file['savename'];
	        //dump($data);
	        $this->subscribe_add($data);
	    }
                                break;
        }
	}
	public function up_meiti($config,$data){
	    delDirAndFile($_SERVER['DOCUMENT_ROOT'] . __ROOT__ . "/Public/uploads/subscribe/" . $_SESSION['member']['email'] . '/' . $data['public_id']);
	    $upload = new \Think\Upload($config);
	    $info = $upload -> upload();
	    //dump($info);
	    if (!$info) {
	        $this -> error($upload -> getError());
	    } else {
	        $file = $info['file'];
	        $data['path']=$_SERVER['DOCUMENT_ROOT'] . __ROOT__ . "/Public/uploads/subscribe/" . $_SESSION['member']['email'] . '/' . $data['public_id'].'/'.$file['savename'];
	        if($info['filepath']){
	            $data['filepath']=$info['filepath']['savepath'] . $info['filepath']['savename'];
	        }
	        $type=$data['msgtype'];
	        if($data['msgtype']=="thumb"){
	            $data['musicurl']=$info['filepath']['savepath'] . $info['filepath']['savename'];
	            $data['hqmusicurl']=$info['filepath']['savepath'] . $info['filepath']['savename'];
	        }
	        $filepath = $data['path'];
	        $result=upload_file_to_weixin($type,$filepath);
	        $obj=json_decode($result);
	        if($obj->created_at){
	            //dump($obj);
	            $data['created_at']=$obj->created_at;
	            $data['mediaid']=$obj->media_id;
	            if($data['msgtype']=="thumb"){
	                $data['thumbbediaid']=$obj->thumb_media_id;
	                $data['msgtype']="music";
	            }
	            $this->subscribe_add($data);
	        }else{
	            if(!$obj->errcode){
	                $this -> error("对不起，无响应！");
	            }
	            $this -> error("上传失败！错误代码为".$obj->errcode);
	        }
	    }
	}
	public function subscribe_add($data){
	    $public_id=$data['public_id'];
	    $subscribe=M('subscribe');
	    $result=$subscribe->where("public_id='$public_id'")->select();
	    if($result){
	        $subscribe->where("public_id='$public_id'")->delete();
	        $result=$subscribe->add($data);
	    }else{
	        $result=$subscribe->add($data);
	    }
	    if($result){
	        $this -> success('设置成功！', 'subscribe');
	    }else{
	         $this -> error('设置失败！');
	    }
	}
	public function allplug(){
	    $nowPage = isset($_GET['p'])?$_GET['p']:1;
	    $plug=D('Plug');
	    $installiert_plug = D('installiert_plug');
	    $plug_list = $plug->page($nowPage.',10')->select();
	    $count      = $plug->count();
	    $Page       = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数(25)
	    $Page->setConfig('header','篇记录');
	    $Page->setConfig('prev',"上一页");
	    $Page->setConfig('next','下一页');
	    $Page->setConfig('first','第一页');
	    $Page->setConfig('last','第二页');
	    $show       = $Page->show();// 分页显示输出
	    // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
	    $pub_id = $_SESSION['now_pub']['id'];
	    $uid=$_SESSION['member']['uid'];
	    foreach ($plug_list as $key=>$val){
	        $p_id=$val['id'];
	        $installiert_plug_list = $installiert_plug -> where("pub_id='$pub_id' and uid='$uid' and p_id='$p_id'") -> find();
	        if($installiert_plug_list){
	            $plug_list[$key]['installed']=1;
	        }else{
	            $plug_list[$key]['installed']=0;
	        }
	        
	    }
	    //dump($plug_list);
	    $this->assign('page',$show);// 赋值分页输出
	    $this -> assign('plug_list', $plug_list);
	    $this->display();
	}
	public function install_plug(){
	    $installiert_plug = D('installiert_plug');
	    $data['p_id']=$_GET['id'];
	    $data['uid']=$_SESSION['member']['uid'];
	    $data['pub_id'] = $_SESSION['now_pub']['id'];
	    $result=$installiert_plug->add($data);
	    if($result){
	        echo "true";
	    }
	}
	public function installedplug(){
	    $nowPage = isset($_GET['p'])?$_GET['p']:1;
	    $pub_id = $_SESSION['now_pub']['id'];
	    $uid=$_SESSION['member']['uid'];
	    $plug=D('Plug');
	    $installiert_plug = D('installiert_plug');
	    $installiert_plug_list = $installiert_plug -> where("pub_id='$pub_id' and uid='$uid'")->page($nowPage.',10') -> select();
	    $count      = $installiert_plug -> where("pub_id='$pub_id' and uid='$uid'")->count();
	    $Page       = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数(25)
	    $Page->setConfig('header','篇记录');
	    $Page->setConfig('prev',"上一页");
	    $Page->setConfig('next','下一页');
	    $Page->setConfig('first','第一页');
	    $Page->setConfig('last','第二页');
	    $show       = $Page->show();// 分页显示输出
	    // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
	    foreach ($installiert_plug_list as $key=>$val){
	        $id=$val['p_id'];
	        $plug_list = $plug -> where("id='$id'") -> find();
	        //dump($plug_list);
	        $installiert_plug_list[$key]['plug_name']=$plug_list['plug_name'];
	        $installiert_plug_list[$key]['intraduce']=$plug_list['intraduce'];
	        $installiert_plug_list[$key]['plug_admin']=$_SERVER['SERVER_NAME']."/plug".$plug_list['plug_admin'];
	    }
	    //dump($plug_list);
	    $this->assign('page',$show);// 赋值分页输出
	    $this -> assign('plug_list', $installiert_plug_list);
	    $this->display();
	}
	function isonlock(){
	    $installiert_plug = D('installiert_plug');
	    $data=I("get.");
	    $pub_id=$data['pub_id'];
	    $p_id=$data['p_id'];
	    $textmenu=M("Textmenu");
	    $textmenu->where("pub_id='$pub_id' and p_id='$p_id'")->delete();
	    $result=$installiert_plug->save($data);
	    if($result){
	        echo "true";
	    }
	    //dump($data);
	}
	public function textmenu(){
	    $plug=D('Plug');
	    $member_public = D('Member_public');
	    $installiert_plug = D('installiert_plug');
	    $textmenu=M("Textmenu");
	    $pub_id = $_SESSION['now_pub']['id'];
	    $uid=$_SESSION['member']['uid'];
	    $installiert_plug_list = $installiert_plug -> where("pub_id='$pub_id' and uid='$uid' and isunlock=1")-> select();
	    foreach ($installiert_plug_list as $key=>$val){
	        $id=$val['p_id'];
	        //echo $id;
	        $plug_list = $plug -> where("id='$id'") -> find();
	        $keyval=$textmenu->where("pub_id='$pub_id' and p_id='$id'")->getField('key1',true);
	        $installiert_plug_list[$key]['key1']=$keyval[0];
	        $installiert_plug_list[$key]['plug_name']=$plug_list['plug_name'];
	        $installiert_plug_list[$key]['intraduce']=$plug_list['intraduce'];
	        $installiert_plug_list[$key]['plug_admin']=$plug_list['plug_admin'];
	    }
	    //dump($installiert_plug_list);
	    $this -> assign('plug_list', $installiert_plug_list);
	    $this->display();
	}
	public function textmenu_process(){
	    $data1=I("post.");
	    $pub_id = $_SESSION['now_pub']['id'];
	    $i=0;
	    $data='';
	    $textmenu=M("Textmenu");
	    $textmenu->where("pub_id='$pub_id'")->delete(); 
	    foreach ($data1 as $key=>$val){
	        if($i++==0){
	            $data['p_id']=$val;
	        }else{
	            $data['key1']=$val;
	            $data['pub_id']=$pub_id;
	            $i=0;
	            //dump($data);
	            $textmenu->add($data);
	        }
	    }
	    $this->success("设置成功！",textmenu);
	}
	public function custom_list(){
	    $custom_res=M("Custom_res");
	    $public_id = $_SESSION['now_pub']['public_id'];
	    $custom_list=$custom_res->where("public_id='$public_id'")->select();
	    //dump($custom_list);
	    $this -> assign('custom_list', $custom_list);
	    $this->display();
	}
	public function delete_custom_res(){
	    $custom_res=M("Custom_res");
	    $id=$_GET['id'];
	    $result=$custom_res->where("id='$id'")->delete();
	    if($result){
	        $this->success("删除成功！",custom_list);
	    }else{
	        $this->error("操作失败！");
	    }
	}
	public function delete_custom_ress(){
	    $custom_res=M("Custom_res");
	    $public_id = I('get.public_id');
	    $public_id = substr($public_id, 0, -1);
	    $public_id = explode(",", $public_id);
	    foreach ($public_id as $value) {
	        $result=$custom_res->where("public_id='$value'")->delete();
	    }
	    echo "true";
	}
	public function custom_add_pro(){
	    $data=I("post.");
	    switch ($data['msgtype']){
	        case 'text':
	            $this->custom_add_process($data);
	            break;
	        case 'image':
	            $config = array(
	            'maxSize' => 1024000,
	            'rootPath' => './Public/',
	            'savePath' => '/uploads/custom/' . $_SESSION['member']['email'] . '/',
	            'replace' => 'true',
	            'exts' => array('jpg'),
	            'subName' => $data['public_id'],
	            );
	            $this->up_meiti1($config,$data);
	            break;
	        case 'voice':
	            $config = array(
	            'maxSize' => 1024000,
	            'rootPath' => './Public/',
	            'savePath' => '/uploads/custom/' . $_SESSION['member']['email'] . '/',
	            'replace' => 'true',
	            'exts' => array('amr','mp3'),
	            'subName' => $data['public_id'],
	            );
	            $this->up_meiti1($config,$data);
	            break;
	        case 'video':
	            $config = array(
	            'maxSize' => 10240000,
	            'rootPath' => './Public/',
	            'savePath' => '/uploads/custom/' . $_SESSION['member']['email'] . '/',
	            'replace' => 'true',
	            'exts' => array('amr','mp4'),
	            'subName' => $data['public_id'],
	            );
	            $this->up_meiti1($config,$data);
	            break;
	        case 'thumb':
	            $config = array(
	            'maxSize' => 10240000,
	            'rootPath' => './Public/',
	            'savePath' => '/uploads/custom/' . $_SESSION['member']['email'] . '/',
	            'replace' => 'true',
	            'exts' => array('amr','mp3','jpg'),
	            'subName' => $data['public_id'],
	            );
	            $this->up_meiti1($config,$data);
	            break;
	        case 'news':
	            $config = array(
	            'maxSize' => 10240000,
	            'rootPath' => './Public/',
	            'savePath' => '/uploads/custom/' . $_SESSION['member']['email'] . '/',
	            'replace' => 'true',
	            'exts' => array('jpg'),
	            'subName' => $data['public_id'],
	            );
	            //delDirAndFile($_SERVER['DOCUMENT_ROOT'] . __ROOT__ . "/Public/uploads/custom/" . $_SESSION['member']['email'] . '/' . $data['public_id']);
	            $upload = new \Think\Upload($config);
	            $info = $upload -> upload();
	            //dump($info);
	            if (!$info) {
	                $this -> error($upload -> getError());
	            } else {
	                $file = $info['file'];
	                //$data['picurl'] = $arr['__PUBLIC__'].$file['savepath'] . $file['savename'];
	                $data['picurl'] = $file['savepath'] . $file['savename'];
	                //dump($data);
	                $this->custom_add_process($data);
	            }
	            break;
	    }
	}
	public function up_meiti1($config,$data){
	    //delDirAndFile($_SERVER['DOCUMENT_ROOT'] . __ROOT__ . "/Public/uploads/custom/" . $_SESSION['member']['email'] . '/' . $data['public_id']);
	    $upload = new \Think\Upload($config);
	    $info = $upload -> upload();
	    //dump($info);
	    if (!$info) {
	        $this -> error($upload -> getError());
	    } else {
	        $file = $info['file'];
	        $data['path']=$_SERVER['DOCUMENT_ROOT'] . __ROOT__ . "/Public/uploads/custom/" . $_SESSION['member']['email'] . '/' . $data['public_id'].'/'.$file['savename'];
	        if($info['filepath']){
	            $data['filepath']=$info['filepath']['savepath'] . $info['filepath']['savename'];
	        }
	        $type=$data['msgtype'];
	        if($data['msgtype']=="thumb"){
	            $data['musicurl']=$info['filepath']['savepath'] . $info['filepath']['savename'];
	            $data['hqmusicurl']=$info['filepath']['savepath'] . $info['filepath']['savename'];
	        }
	        $filepath = $data['path'];
	        $result=upload_file_to_weixin($type,$filepath);
	        $obj=json_decode($result);
	        //dump($result);
	        if($obj->created_at){
	            //dump($obj);
	            $data['created_at']=$obj->created_at;
	            $data['mediaid']=$obj->media_id;
	            if($data['msgtype']=="thumb"){
	                $data['thumbbediaid']=$obj->thumb_media_id;
	                $data['msgtype']="music";
	            }
	            $this->custom_add_process($data);
	        }else{
	            if(!$obj->errcode){
	                $this -> error("对不起，无响应！");
	            }
	            $this -> error("上传失败！错误代码为".$obj->errcode);
	        }
	    }
	}
	public function custom_add_process($data){
	    $public_id=$data['public_id'];
	    $custom_res=M('Custom_res');
	    $result=$custom_res->add($data);
	    if($result){
	        $this -> success('设置成功！', 'custom_list');
	    }else{
	        $this -> error('设置失败！');
	    }
	}
	public function voicemenu(){
	    $voiceopen=M("Voiceopen");
	    $data=I('get.');
	    $pub_id=$_SESSION['now_pub']['public_id'];
	    //echo $pub_id;
	    $result=$voiceopen->where("pub_id='$pub_id'")->find();
	    $result['public_id']=$data['public_id'];
	    //dump($result);
	    $this -> assign('voicemenu', $result);
	    $this->display();
	}
	public function voicemenu_pro(){
	    $voiceopen=M("Voiceopen");
	    $data=I('get.');
	    $pub_id=$data['pub_id'];
	    //dump($data);
	    $result=$voiceopen->where("pub_id='$pub_id'")->save($data);
	    if(!$result){
	        $result=$voiceopen->add($data);
	    }
	    if($result){
	        $this -> success('设置成功！', 'voicemenu');
	    }else{
	        $this -> error('设置失败！');
	    }
	}
	public function newspush(){
	    $this->display();
	}
}